package com.yunxin.core.infra.persistence.repository.channel;

import com.yunxin.core.domain.model.channel.ChannelPromotionMerchantConfig;
import com.yunxin.core.domain.model.channel.ChannelPromotionMerchantConfigRepository;
import com.yunxin.core.infra.persistence.converter.ChannelConvertor;
import com.yunxin.core.infra.persistence.entity.channel.ChannelPromotionMerchantConfigDO;
import com.yunxin.core.infra.persistence.mapper.channel.ChannelPromotionMerchantConfigExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2024-01-25
 */
@Repository
@RequiredArgsConstructor
public class ChannelPromotionMerchantConfigRepositoryImpl implements ChannelPromotionMerchantConfigRepository {

    private final ChannelPromotionMerchantConfigExtendMapper channelPromotionMerchantConfigExtendMapper;

    private final ChannelConvertor channelConvertor;

    @Override
    public boolean saveChannelPromotionMerchantConfig(ChannelPromotionMerchantConfig channelPromotionMerchantConfig) {
        ChannelPromotionMerchantConfigDO channelPromotionMerchantConfigDO = channelConvertor.formChannelPromotionMerchantConfig(channelPromotionMerchantConfig);
        int result = channelPromotionMerchantConfigExtendMapper.insertSelective(channelPromotionMerchantConfigDO);
        return result > 0;
    }

    @Override
    public boolean updateChannelPromotionMerchantConfig(ChannelPromotionMerchantConfig channelPromotionMerchantConfig) {
        ChannelPromotionMerchantConfigDO channelPromotionMerchantConfigDO = channelConvertor.formChannelPromotionMerchantConfig(channelPromotionMerchantConfig);
        int result = channelPromotionMerchantConfigExtendMapper.updateByPrimaryKeySelective(channelPromotionMerchantConfigDO);
        return result > 0;
    }

    @Override
    public ChannelPromotionMerchantConfig getChannelPromotionMerchantConfigByChannelPromotionCode(String channelPromotionCode) {
        ChannelPromotionMerchantConfigDO channelPromotionMerchantConfigDO = channelPromotionMerchantConfigExtendMapper.selectChannelPromotionMerchantConfigByChannelCode(channelPromotionCode);
        return channelConvertor.toChannelPromotionMerchantConfig(channelPromotionMerchantConfigDO);
    }
}
